package karaoke.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;

import junit.framework.Assert;

import karaoke.excepcion.DAOExcepcion;
import karaoke.modelo.JsonResult;
import karaoke.modelo.Local;
import karaoke.modelo.Sala;
import karaoke.negocio.GestionLocales;
import karaoke.negocio.GestionSalas;

/**
 * Servlet implementation class RecuperaPostServlet
 */
@WebServlet("/admin/SalaEliminarServlet")
public class SalaEliminarServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SalaEliminarServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	   
       

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub

		Gson gson = new Gson();
		JsonResult result = new JsonResult();
		String message = "";
		int tipoMsg = JsonResult.WARNING;
		
	    int idSala = Integer.parseInt(request.getParameter("EliId"));
 
        Sala nuevo = null;
		GestionSalas negocio = new GestionSalas();
		try {
			 negocio.eliminarLogicamente(idSala,true);
			 nuevo = negocio.obtener(idSala);
			 
			 if (nuevo.iseLog()) {
					tipoMsg = JsonResult.SUCCESS;
					message = "["+nuevo.getIdSala()+"] Se elimino satisfactoriamente";
				} else {
					tipoMsg = JsonResult.ERROR;
					message = "No se pudo eliminar";
			}
			
		} catch (DAOExcepcion e) {
			message = e.getMessage();
	
		}
	
		
		// Guardando datos en el scope REQUEST
	 	result.addMenssage(tipoMsg, message);
		
	    PrintWriter out = response.getWriter();
		out.println(gson.toJson(result));       
			   

       
	
   } //DoPost
     

	
}
